package com.pro.springbootshop.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.pro.springbootshop.entity.MainClasses;
import com.pro.springbootshop.entity.OtherClasses;
import org.apache.ibatis.annotations.*;
import org.mapstruct.Mapper;

import java.util.List;

@Mapper
public interface OtherClassesMapper extends BaseMapper<OtherClasses> {
    @Select("select * from other_classes where main_class_id = #{main_class_id}")
    List<OtherClasses> selectByMainClassId(@Param("main_class_id")int main_class_id);
    @Select("select * from other_classes")
    @Results(
            {
                    @Result(column = "other_class_id",property = "otherClassId"),
                    @Result(column = "other_class_name",property = "otherClassName"),
                    @Result(column = "main_class_id",property = "mainClassId"),
                    @Result(column = "main_class_id",property = "mainClasses",javaType = MainClasses.class,
                            one=@One(select = "com.pro.springbootshop.mapper.MainClassesMapper.selectById")
                    )
            }
    )
    List<OtherClasses> selectAllByOther();
    @Select("select * from other_classes limit #{pageNo},#{limit}")
    @Results(
            {
                    @Result(column = "other_class_id",property = "otherClassId"),
                    @Result(column = "other_class_name",property = "otherClassName"),
                    @Result(column = "main_class_id",property = "mainClassId"),
                    @Result(column = "main_class_id",property = "mainClasses",javaType = MainClasses.class,
                            one=@One(select = "com.pro.springbootshop.mapper.MainClassesMapper.selectById")
                    )
            }
    )
    List<OtherClasses> getOtherClassesList(@Param("pageNo") Integer pageNo,@Param("limit") Integer limit);
    @Select("select * from other_classes where other_class_name=#{otherClassName} and main_class_id=#{mainClassId}")
    OtherClasses selectOtherClass(@Param("mainClassId")int mainClassId,@Param("otherClassName")String otherClassName);
}
